<!DOCTYPE html>
<html lang="zh_CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios+vue</title>
</head>

<body>
    <div id="app">
        <input type="button" value="提取笑话" @click="getJoke">
        <p>{{ joke }}</p>
    </div>

    <!-- 开发环境版本 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 官网提供的axios在线地址 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        /*
            接口1：随机笑话
            请求地址：https://autumnfish.cn/api/joke
            请求方法：无
            响应内容：随机笑话
        */
        var app = new Vue({
            el: "#app",
            data: {
                joke: "很好笑的笑话"
            },
            methods: {
                getJoke: function () {
                    // console.log(this.joke)
                    var that = this;
                    axios.get("https://autumnfish.cn/api/joke").then(
                        function (response) {
                            // 此时的this已经和上面的this不一样了。所以将this存起来，存为that
                            // console.log(response)
                            console.log(response.data);
                            that.joke = response.data;

                        }
                    )
                }
            }
        })
    </script>
</body>

</html>